package methodEmbedding.Standing_Ovation.S.LYD1136;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class code1 {



	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		int Smax;
		String aud_str;
		int T;
		int Ni;
		int Sum;
		int counter;
		String answer;

		String file_name = "src/a_problem/A-small-attempt5.in";
		String output_file = "src/a_problem/answer.txt";
		try{
			File file1 = new File(file_name);
			FileReader filereader = new FileReader(file1);
			BufferedReader br = new BufferedReader(filereader);

			File file2 = new File(output_file);
			BufferedWriter bw = new BufferedWriter(new FileWriter(file2));

			//??????????????????
			String str = br.readLine();
			T = Integer.parseInt(str);

			//????????????????????????
			for(int i=0; i<T; i++) {
				counter = 0;
				Sum = 0;
				str = br.readLine();

				char Smax_char = str.charAt(0);
				Smax = Integer.parseInt("" + str.charAt(0));

				//????????????
				for(int j=0; j<=Smax; j++){
					Ni = Integer.parseInt("" + str.charAt(j+2) );

					if( Ni > 0 && Sum + counter < j) { //????????????????????????????????????????????????
						counter += ( j - ( Sum + counter) ); //????????????

					}

					//???????????????????????????

					Sum += Ni;

				}

				answer = "Case  #" + (i+1) + ": " + counter;

				bw.write(answer);
				if(i < T-1 ){
					bw.newLine();
				}
			}

			br.close();
			bw.close();

		}catch(FileNotFoundException e){
		  System.out.println(e);
		}catch(IOException e){
			  System.out.println(e);
		}
	}

}
